//
//  ChatTargetView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/11/5.
//

import SwiftUI

//引用试图
struct ChatTargetView: View {
    var bean: ChatBean
    var body: some View {
        let picture = bean.getTargetPicture()
        Menu {
            Button("定位位置") {
                //发送通知
                NotificationCenter.default.post(name: .searchChat, object: bean.objectId)
            }
        } label: {
            HStack {
                Text(bean.getTargetChatStr())
                    .font(.system(size: 12))
                    .foregroundStyle(.bgNormalText4)
                    .lineLimit(2)
                if let picture = picture {
                    pictureView(picture: picture).padding(.leading, 30)
                }
                   
            }.padding(.horizontal, 10)
                .padding(.vertical, 5)
                .background(Color.hex("#8A8A8A").opacity(0.2))
                .cornerRadius(5)
        }
        
    }
}

extension ChatTargetView {
    func pictureView(picture: EmojiPictureBean) -> some View {
        let itemWidth: CGFloat = 40
        let itemHeight: CGFloat = 40
        return VStack {
            if let mediaItem = EmojiPictureUtils.shared.getMediaItem(picture) {
                PictureItemView(item: mediaItem, itemWidth: itemWidth, itemHeight: itemHeight, cornerRadius: 5)
            } else {
                Image(.appDefaultLogo)
                    .resizable()
                    .scaledToFill()
                    .padding(.horizontal, itemWidth / 4)
                    .padding(.vertical, itemWidth / 4)
            }
        }.frame(width: itemWidth, height: itemHeight)
            .clipShape(RoundedRectangle(cornerRadius: 5))
    }
}
#Preview {
    ChatTargetView(bean: ChatBean())
}
